from dotenv import load_dotenv
import os
from pathlib import Path

load_dotenv()

# 项目根目录
BASE_DIR = Path(__file__).resolve().parent


class Settings:
    SECRET_KEY = os.getenv("SECRET_KEY")
    ALGORITHM = os.getenv("ALGORITHM")
    ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", 30))
    DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./data/face.db")
    MILVUS_HOST = os.getenv("MILVUS_HOST", "localhost")
    MILVUS_PORT = os.getenv("MILVUS_PORT", "19530")
    FACE_COLLECTION_NAME = os.getenv("FACE_COLLECTION_NAME", "default_collection")

    # 新增日志配置
    LOG_LEVEL = os.getenv("LOG_LEVEL", "DEBUG")
    LOG_DIR = BASE_DIR / "logs"
    LOG_FILE = LOG_DIR / "face_api.log"
    LOG_ROTATION = "10 MB"  # 每个日志文件最大10MB
    LOG_RETENTION = 5  # 最多保留5个日志文件
    LOG_FORMAT = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
    # 新增静态文件配置
    STATIC_DIR = BASE_DIR / "static"
    FACE_IMAGE_DIR = STATIC_DIR / "face_images"
    FACE_RESULTS_IMAGE_DIR = STATIC_DIR / "face_results_images"

    @classmethod
    def create_dirs(cls):
        """创建必要的目录"""
        cls.STATIC_DIR.mkdir(exist_ok=True)
        cls.FACE_IMAGE_DIR.mkdir(exist_ok=True)
        cls.LOG_DIR.mkdir(exist_ok=True)


settings = Settings()
settings.create_dirs()
